package com.gouaixin.bee.beeframework2.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.activity.B6_ziliaoActivity;
import com.gouaixin.bee.beeframework2.adapter.B2_fensiAdapter;
import com.gouaixin.bee.beeframework2.bean.ZhenxinhuaFriend;
import com.gouaixin.bee.beeframework2.dao.zhenxinhuaFriendDao;
import com.gouaixin.bee.beeframework2.tool.mLog;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/3/9.
 */
//关注我的
public class B2_guanzhuWoFragment extends Fragment {
    View mainView;

    ListView listView;
    B2_fensiAdapter adapter;
    List<ZhenxinhuaFriend> datas=new  ArrayList<ZhenxinhuaFriend>();


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mainView = inflater.inflate(R.layout.b2_guanzhuwo, null);
        adapter=new B2_fensiAdapter(getActivity());

        initView();

        setData();

        setListener();


        return mainView;
    }

    private void setData() {


        datas = zhenxinhuaFriendDao.query(getActivity());
        if (datas!=null) {
            adapter.setData(datas);
            adapter.notifyDataSetChanged();

            mLog.e("关注我的datas:" + new Gson().toJson(datas));


        }


    }

    private void setListener() {
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if(!datas.equals("")){
                    Intent it = new Intent().setClass(getActivity(), B6_ziliaoActivity.class);
                    it.putExtra("HerId",datas.get(position).getJid());
                    startActivity(it);
                }



            }
        });

    }

    private void initView() {
        listView = (ListView) mainView.findViewById(R.id.list);

    }
}
